
const { default: axios } = require('axios');
const { news } = require('./final.json');
const fs = require('fs');

let result = [];

async function fn() {
    for (let i = 0; i < news.length; i++) {
        //获取数据
        let item = news[i];
        //拼接 url
        let url = `http://c.m.163.com/nc/article/${item.docid}/full.html`;
        //获取数据
        let { data } = await axios(url);
        //获取key
        let key = Object.keys(data)[0];
        //拼接数据
        item.body = data[key].body;
        //图片
        item.imgArr = data[key].img;
        //分类
        item.type = data[key].category;
        //关键字
        item.keywords = data[key].dkeys;
        //介绍
        item.intro = data[key].headText;
        //压入
        result.push(item);
    }
    fs.writeFileSync(__dirname + '/t.json', JSON.stringify({news: result}))
}

fn();

